package com.xpgk.mvc.btoShop;

import java.util.List;

import com.jfinal.log.Log;
import com.xpgk.annotation.Table;
import com.xpgk.mvc.base.BaseModel;
import com.xpgk.mvc.bstockHandover.StockHandover;


/**
 * 库存交接表
 */
@SuppressWarnings("unused")
@Table(tableName = BtoShop.table_name)
public class BtoShop extends  BaseModel<BtoShop>{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6458457151699439939L;

	private static final Log log = Log.getLog(BtoShop.class);

	public static final BtoShop dao = new BtoShop().dao();

	/**
	 * 表名称
	 */
	public static final String table_name = "sb_customer_toshop";

	/**
	 * 字段描述：主键 字段类型：character varying 长度：32
	 */
	public static final String column_ids = "ids";
//	/**
//	 * 字段描述：机构ids 字段类型：character varying 长度：32
//	 */
//	public static final String column_organIds = "organIds";
	/**
	 * 字段描述：顾客ids 字段类型：character varying 长度：32
	 */
	public static final String column_customerIds = "customerIds";
	/**
	 * 字段描述：转入店铺ids 字段类型：character varying 长度：32
	 */
	public static final String column_intoShopIds = "intoShopIds";
	/**
	 * 字段描述：转出店铺ids  字段类型：character varying 长度：32
	 */
	public static final String column_outShopIds = "outShopIds";
	/**
	 * 字段描述：转入店是否确认（0未确认1已确认） 字段类型：char 长度：1
	 */
	public static final String column_isConfirm = "isConfirm";
	/**
	 * 字段描述：转出时间  字段类型：date
	 */
	public static final String column_outTime = "outTime";
	/**
	 * 字段描述：转入时间  字段类型：date
	 */
	public static final String column_intoTime = "intoTime";
	/**
	 * 字段描述：转出操作者ids 字段类型：character varying 长度：32
	 */
	public static final String column_outUserIds = "outUserIds";
	/**
	 * 字段描述：确认转入操作者ids 字段类型：character varying 长度：32
	 */
	public static final String column_confirmUserIds = "confirmUserIds";
	/**
	 * 字段描述：转店原因 字段类型：character varying 长度：32
	 */
	public static final String column_toShopReason = "toShopReason";
	/**
	 * 字段描述：首次减重时间 字段类型：character varying 长度：32
	 */
	public static final String column_firstLoseWeightTime = "firstLoseWeightTime";
	/**
	 * 字段描述：最后减重时间  字段类型：character varying 长度：32
	 */
	public static final String column_lastLoseWeightTime = "lastLoseWeightTime";
	/**
	 * 字段描述：最后体重 字段类型：character varying 长度：32
	 */
	public static final String column_lastWeight = "lastWeight";
	/**
	 * 字段描述：减重次数 字段类型：character varying 长度：32
	 */
	public static final String column_delWeightNum = "delWeightNum";
	/**
	 * 字段描述：旧店协议编号 字段类型：character varying 长度：32
	 */
	public static final String column_oldAgreementNumber = "oldAgreementNumber";
	
	/**
	 * 字段描述：更新时间 字段类型：character varying 长度：32
	 */
	public static final String column_gxsj = "gxsj";
	
	/**
	 * 字段描述：更新时间 字段类型：character varying 长度：32
	 */
	public static final String column_dataStatus = "dataStatus";
	/**
	 * 字段描述：时间 字段类型：datetime
	 */
	public static final String column_updateDate = "updateDate";
	/**
	 * 字段描述：时间 字段类型：datetime
	 */
	public static final String column_updateId = "updateId";
	
	
	

	/**
	 * sqlId : sb.toshop.getIntoShops
	 * 描述：查询某点转入顾客
	 */
	public static final String sqlId_getIntoShops= "sb.toshop.getIntoShops";
	
	/**
	 * sqlId : sb.toshop.getOutShopCus
	 * 描述：查询某点转入顾客
	 */
	public static final String sqlId_getOutShopCus = "sb.toshop.getOutShopCus";
	
	/**关联查询，获取某店某顾客转出记录
	 * 
	 * @param customerIds
	 * @param outOrganIds
	 * @return
	 */
	public  BtoShop  getOutShop(String customerIds,String outOrganIds)
	{
		String  sql="SELECT * ,sys_getCodeName(toShopReason) reason from  sb_customer_toshop  where  customerIds=? and  outShopIds=?";
		return  BtoShop.dao.findFirst(sql,customerIds,outOrganIds);
	}
	/**关联查询，获取某店某顾客转入
	 * 
	 * @param customerIds
	 * @param outOrganIds
	 * @return
	 */
	public  BtoShop  getIntoShop(String customerIds,String intoOrganIds)
	{
		String  sql="SELECT *,sys_getCodeName(toShopReason) reason  from  sb_customer_toshop  where  customerIds=? and  intoShopIds=?";
		return  BtoShop.dao.findFirst(sql,customerIds,intoOrganIds);
	}
//	/**关联查询，获取某店转入记录
//	 * 
//	 * @param intoOrganIds
//	 * @return
//	 */
//	public  List<BtoShop>  getIntoShops(String intoOrganIds)
//	{
//		String  sql="SELECT  sc.ids cusids,sc.`name` cusname,sc.phone cusphone,scd.nowWeight cuslastweight, COUNT(ss.ids) servicecount,so.`name` outshop from  sb_customer_toshop  st "
//				+" LEFT JOIN  sb_customer_service  ss  on ss.customerID=st.customerIds"
//				+" LEFT JOIN   sb_customer  sc  on sc.ids=st.customerIds"
//				+" LEFT JOIN   sb_customer_detail  scd  on  scd.customerIds=st.customerIds"
//				+" LEFT JOIN   sys_organization  so  on  so.ids=st.outShopIds"
//				+" WHERE  st.intoShopIds=?  and  isConfirm='0' GROUP BY  st.customerIds";
//		return  BtoShop.dao.find(sql,intoOrganIds);
//	}
	
}
